<template>
	<view class="order-main">
		<view class="order-search">
			<u-search placeholder="搜索订单" v-model="keyword" bg-color="#fff" :showAction="false"
				@search="seachList()"></u-search>
		</view>
		<view class="order-type">
			<view class="item" v-for="(item,index) in typeList" :key="index" :class="current==item.id?'active':''"
				@click="changeType(item.id)">
				{{item.name}}
			</view>
		</view>
		<view class="order-box">
			<view class="order-list" v-for="(item,index) in list">
				<view class="top">
					<view class="time">
						下单时间：{{item.pay_at}}
					</view>
				</view>
				<view class="mid">
					<image :src="item.product_picture" mode="" class="img"></image>
					<view class="mid-center">
						<view class="name">
							{{item.product_title}}
						</view>
						<view class="mid-yj">
							预估佣金￥{{item.products.subsidy_amount}}
						</view>
					</view>
					<view class="mid-right">
						<view class="num">
							￥{{item.order_amount}}
						</view>
						<view>
							{{returnStatus(item.status)}}
						</view>
					</view>
				</view>
				<view class="bottom">
					<view class="bottom-left">
						订单号：{{item.order_id}}
					</view>
					<view class="bottom-right">
						<text v-if="item.is_settlement==1">结算状态:未结算</text>
						<text v-else>结算状态:已结算</text>	
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				size: 10,
				keyword: '',
				status: 0,
				current: 1,
				typeList: [{
					name: '全部',
					id: 1
				}, {
					name: '已付款',
					id: 2
				}, {
					name: '已收货',
					id: 3
				}, {
					name: '已结算',
					id: 4
				}, {
					name: '已失效',
					id: 5
				}],
				list: []
			}
		},
		mounted() {
			this.getData()
		},
		methods: {
			returnStatus(status){
				switch(status){
					case 0:
					return '待支付'
					break;
					case 1:
					return '已支付'
					break;
					case 2:
					return '已取消'
					break;
					case 3:
					return '已完成'
					break;
					case 4:
					return '已退款'
					break;
					default:
					return '状态异常'
					break;
				}
			},
			seachList() {
				this.current = 1
				this.getData()
			},
			changeType(id) {
				this.current = id
				this.getData()
			},
			getData() {
				let type = this.current
				let data = {
					limit: this.size,
					page: this.page,
					keyword: this.keyword,
				}
				switch (type) {
					case 1:
						break;
					case 2:
						data['status'] = 1
						break;
					case 3:
						data['status'] = 3
						break;
					case 4:
						data['is_settlement'] = 2
						break;
					case 5:
						data['status'] = 2
						break;
					default:
						break;
				}

				this.$api.shareList(data).then(res => {
					this.list = res.list
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.order-main {
		margin: 20rpx;
	}

	.order-type {

		display: flex;
		justify-content: space-between;
		margin: 20rpx 0;

		.item {
			color: #999;
			font-size: 26rpx;
		}

		.active {
			color: #f09c50;
			font-weight: bold;
		}
	}

	.order-list {
		background: #fff;
		border-radius: 20rpx;
		padding: 20rpx;
		display: flex;
		flex-direction: column;
		gap: 20rpx;
		margin-top: 20rpx;

		.top {
			display: flex;
			justify-content: space-between;
			font-size: 24rpx;
			color: #999;
			border-bottom: 1px solid #eee;
			padding-bottom: 20rpx;
		}

		.mid {
			display: flex;
			justify-content: space-between;
			align-items: center;
			gap: 20rpx;

			.mid-center {
				flex: 1;
				overflow: hidden;
				margin-right: 10rpx;
				display: flex;
				flex-direction: column;
				gap: 60rpx;
				justify-content: space-between;

				.name {
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
				}

				.mid-yj {
					color: #f09c50;
					font-weight: bold;
				}
			}

			.mid-right {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				gap: 60rpx;
				color: #d6be66;
				font-size: 26rpx;

				.num {
					color: #333;
				}
			}
		}

		.bottom {
			display: flex;
			justify-content: space-between;
			align-items: center;
			background: #fafafa;
			height: 60rpx;
			font-size: 26rpx;
			color: #333;
			padding: 0 20rpx;
		}

		.img {
			height: 150rpx;
			width: 150rpx;
		}
	}
</style>